﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Majesty_of_Omega.GUI.Controller;

#endregion

namespace Majesty_of_Omega.GUI.WPFUtil
{
    /// <summary>
    /// Observable class for this project. We need a way, to signal changes to the collection and notify 
    /// wpf, to redraw its contents. This is useful, wenn inner objects are changed, without modifying 
    /// the collection.
    /// </summary>
    /// <remarks>
    /// Look at the MooObservableCollectin in <see cref="ResearchPageController" /> for applied technologies
    /// </remarks>
    /// <typeparam name="T"></typeparam>
    public class MooObservableCollection<T> : ObservableCollection<T>
    {
        /// <summary>
        /// The source collection of this list.
        /// </summary>
        private readonly IEnumerable<T> _sourceList;

        /// <summary>
        /// Initializes a new instance of the <see cref="MooObservableCollection&lt;T&gt;"/> class 
        /// with the given collection
        /// </summary>
        /// <param name="list">The list.</param>
        public MooObservableCollection(IEnumerable<T> list):base(list)
        {
            _sourceList = list;
        }

        /// <summary>
        /// Signal a change to an object in the collection.
        /// </summary>
        public void SignalCollectionChanged()
        {
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }

        /// <summary>
        /// Refreshes the contents of this list
        /// </summary>
        public void Refresh()
        {
            Clear();
            foreach (var sourceItem in _sourceList)
            {
                Add(sourceItem);
            }
        }
    }
}